package club.banyuan;

public class TimerImpl implements Timer {

    private static long startTime;
    private static long stopTime;
    private boolean isStart;

    @Override
    public void start() throws IllegalStateException {
        if (isStart){
            throw new IllegalStateException("已经开始");
        }
        startTime = System.currentTimeMillis();
        isStart = true;
    }

    @Override
    public void stop() throws IllegalStateException {
        if (!isStart){
            throw new IllegalStateException("已经停止");
        }
        stopTime = System.currentTimeMillis();
        isStart = false;
    }

    @Override
    public void reset() {
        startTime = 0;
        stopTime = 0;
        isStart = false;
    }

    @Override
    public long getTimeMillisecond() {
        return stopTime-startTime;
    }
}
